package tests;

import tester.ISame;

public class TestMirror {

}


/*
 * Special class that when compared against another
 * class is only equivalent if the given object is 
 * a "mirror" image of this class. 
 */
class StringMirror{
    public String value;
    
    public StringMirror(String input){
        this.value = input;
    }
    
    public boolean equals(Object o){
        return value.equals(o);
    }
    
}

interface Equality<T>{
    
    public boolean equal(T t1, T t2);
    
}

/* Compares two StringMirrors to see if one mirrors the other */
class IsMirror implements Equality<StringMirror>{
    
    //Defines special equality for a StringMirror
    public boolean equal(StringMirror t1, StringMirror t2){
        String val1 = t1.value;
        String val2 = t2.value;
        
        //Check to make sure they are of equal length so we don't
        //get the false positive of "foo" and "oofo"
        if(val1.length() == val2.length()){
            int i = 0;
            int j = val2.length();
            boolean returnVal = true;
            //Loop down to 0 and up to val1.length
            for(; i < val1.length() && j >= 0 && returnVal; i++, j--)
                if(val1.charAt(i) != val2.charAt(j))
                    returnVal = false; //Will breakout of the loop
            
            return returnVal;
            
        }else{
            //Lengths were not equal
            return false;
        }
        
    }
    
}